<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function red() {
          console.log('red');
        }

        function green() {
          console.log('green');
        }

        function yellow() {
          console.log('yellow');
        }

        async function delay(time) {
          return new Promise(resolve => setTimeout(resolve, time));
        }

        async function changeLight(light, time) {
          await delay(time);
          light();
        }

        async function loop() {
          await changeLight(red, 3000);
          await changeLight(green, 2000);
          await changeLight(yellow, 1000);
          await loop();
        }

        loop();

      </script>
</body>
</html>